#pragma once
#include "where.h"

class Select 
{
protected:
	string  _table;
	sstream _names;
	Where   _where;
public:
	inline Select(const string& t);
	inline string data(void)const;
	inline Select& clear(void);
	inline Select& column(const string&);
	inline Where& where(const string& s="");
};

inline Select::Select(const string& t):_table(t)
{
}
inline Select& Select::clear(void)
{
	_names.str("");
	_where.clear();
	return *this;
}
inline Where& Select::where(const string& s)
{
	if(s.empty() == false)
	{
		_where << s;
	}
	return _where;
}
inline string Select::data(void)const
{
	if(_names.str() == "*")
	{
		return "SELECT " + _names.str() + " FROM " + _table + _where.data();
	}
	return "SELECT " + _names.str() + " FROM " + _table + _where.data();
}
inline Select& Select::column(const string& name)
{
	if(_names.tellp() > 0)
	{
		_names << ",";
	}
	if(name == "*")
	{
		_names.str("");
	}
	_names << name;
	return *this;
}
